package com.demoku.web.application.demoAdmin.impl;

import java.util.List;

import javax.inject.Named;

import org.iff.infra.util.BeanHelper;
import org.iff.infra.util.MapHelper;
import org.iff.infra.util.mybatis.plugin.Page;
import org.iff.infra.util.mybatis.service.Dao;
import org.springframework.transaction.annotation.Transactional;

import com.demoku.web.application.demoAdmin.AppTypeApplication;
import com.demoku.web.application.demoAdmin.vo.AppTypeVO;
import com.demoku.web.domain.demoAdmin.AppType;

/**
 * @author autoCode
 */
@Named("appTypeApplication")
@Transactional
public class AppTypeApplicationImpl implements AppTypeApplication {

	@Override
	public void removeAppType(String appTypeId) {
		AppType.remove(appTypeId);
	}

	@Override
	public AppTypeVO saveAppType(AppTypeVO vo) {
		AppType a = new AppType();
		BeanHelper.copyProperties(a, vo);
		a.save();
		AppTypeVO copyProperties = BeanHelper.copyProperties(new AppTypeVO(), a);
		return copyProperties;
	}

	@Override
	public AppTypeVO getAppTypeVO(String appTypeId) {
		return BeanHelper.copyProperties(new AppTypeVO(), AppType.get(appTypeId));
	}

	@Override
	public List<AppTypeVO> findAll(Page pages) {
		List<AppType> list = Dao.queryList("AppType_Mapping.findAll",
				MapHelper.toMap("page", pages));
		pages.setRows(list);
		return pages.toPage(AppTypeVO.class).getRows();
	}

	@Override
	public Page pageFindAll(Page pages) {
		List<AppType> list = Dao.queryList("AppType_Mapping.findAll",
				MapHelper.toMap("page", pages));
		pages.setRows(list);
		return pages.toPage(AppTypeVO.class);
	}
	
	@Override
	public Page pageFindAllAppType(AppTypeVO vo) {
		Page pages = Page.pageable(10, 1, 0, null);
		
		List<AppType> list = Dao.queryList("AppType_Mapping.pageFindAppType",
				MapHelper.toMap("page", pages , "name", vo.getName()));
		pages.setRows(list);
		return pages.toPage(AppTypeVO.class);
	}

}
